package com.sanrenzu.everybodytv.ui.column;

import android.os.Handler;
import android.os.Looper;

import com.sanrenzu.everybodytv.bean.zxb.ColumItemBean;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by My on 2016/9/5.
 */
public class Columpresenter implements ColumContract.Presenter{

    private ColumContract.View view;
    private ColumContract.Modle modle;

    public Columpresenter(ColumContract.View view){
        this.view =view;
        modle = new ColumModle();
    }

    @Override
    public void onGetColumnItemUrl() {
        modle.onGetColumItem(new Callback<List<ColumItemBean>>() {
            @Override
            public void onResponse(Call<List<ColumItemBean>> call, Response<List<ColumItemBean>> response) {
                final List<ColumItemBean> body = response.body();
                Handler handler = new Handler(Looper.getMainLooper());
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.onGetColumItemBean(body);
                    }
                });
            }

            @Override
            public void onFailure(Call<List<ColumItemBean>> call, Throwable t) {
                Handler handler = new Handler(Looper.getMainLooper());
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.onGetColumItemBeanFailed("网路访问失败");
                    }
                });

            }
        });
    }
}
